var lengthOfLastWord = function (s) {
    s = s.trim()
    let index = s.lastIndexOf(' ')
    if (index == -1) {
        return s.length
    } else {
        return s.slice(index + 1).length
    }
};
let s = "moon  "
lengthOfLastWord(s)